
layui.use(['table', 'form'], function () {
    var table = layui.table;
    var form = layui.form;
    // 第一个实例
    tableIns =
        table.render({
            elem: '#test'
            , height: 'full-200'
            , url: '/findUserBy' //数据接口
            , cellMinWidth: 80
            , page: true //开启分页
            , request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , cols: [
                [ //表头id
                    {type: 'checkbox'}
                    , {field: 'name', title: '姓名', align: 'center', sort: true}
                    , {
                    field: 'position', title: '职位', align: 'center', sort: true, templet: function (d) {
                        if (d.position == 1) {
                            return "测试工程师"
                        } else if (d.position == 2) {
                            return "前端开发"
                        } else if (d.position == 3) {
                            return "部门主管"
                        } else if (d.position == 4) {
                            return "行政"
                        } else if (d.position == 0) {
                            return "java开发"
                        } else {
                            return ""
                        }
                    }
                }
                    , {field: 'phone', title: '电话号码', sort: true, align: 'center'}
                    , {field: 'address', title: '地址', sort: true, align: 'center'}
                ]
            ]
        });

    //查询提交数据并重载
    form.on('submit(formSub)', function (data) {
        var filed = data.field;
        //执行重载
        tableIns.reload({
            where: {
                name: filed.name
                , position: filed.position
                , phone: filed.phone
            }, page: {
                curr: 1
            }
        })
        return false;
    });
})

